package com.gmail.gwanndan.common.auth;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.gmail.gwanndan.common.hibernate.AbstractEntity;

/**
 * @author Dennis Ahaus, dennis.ahaus@gmail.com
 *
 */
@Entity
@Table(name = "roles")
public class Role extends AbstractEntity {

	@Id
	@GeneratedValue
	private int id = -1;

	private String name;
	private String description;

	@ManyToMany
	@Cascade(value = CascadeType.ALL)
	private List<Permission> permissions;

	public Role() {
	}

	public Role(int id, String name, String description) {
		super();
		this.id = id;
		this.name = name;
		this.description = description;
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		Role role = (Role) obj;
		if (getName().equals(role.getName()) && getId() == role.getId()) {
			return true;
		}
		return false;
	}

	public List<Permission> getPermissions() {
		return permissions;
	}

	public void setPermissions(List<Permission> permissions) {
		this.permissions = permissions;
	}

}
